var a = getApp(), t = require("../../api.js");

Page({
    data: {
        data: {
            number: "",
            addresss: "",
            names: ""
        },
        img: ""
    },
    onLoad: function(a) {
        this.click();
    },
    subbtn: function() {
        var t = this.data.data;
        if (console.log(t), "1" == t.number) return a.showToast("请拍车牌号", 0), !1;
        if ("1" == t.addresss) return a.showToast("请输入目的地", 0), !1;
        var e = {
            startAddress: {
                address: t.name,
                location: {
                    lat: t.lat,
                    lng: t.lng
                }
            },
            endAddress: {
                address: t.names,
                location: {
                    lat: t.lats,
                    lng: t.lngs
                }
            },
            card_number: t.number
        };
        a.Request({
            url: "driver_order/place_an_order",
            method: "post",
            data: e
        }).then(function(t) {
            1 == t.code ? a.showToast(t.msg, 0, 1500, function() {
                a.navTo("/pages/driverOrder/orderedStatus/orderedStatus?order_no=" + t.data.order_no);
            }) : a.showToast(t.msg, 0);
        });
    },
    address: function() {
        var t = this, e = t.data.data;
        wx.chooseLocation({
            success: function(a) {
                e.addresss = a.address, e.names = a.name, e.lats = a.latitude, e.lngs = a.longitude, 
                t.setData({
                    data: e
                });
            },
            fail: function(t) {
                a.showToast("打开地图失败", 0);
            }
        });
    },
    takePhoto: function() {
        var e = this, o = wx.createCameraContext();
        wx.showLoading({
            title: "识别中"
        });
        var s = e.data.data;
        o.takePhoto({
            quality: "high",
            success: function(o) {
                console.log(o), wx.saveImageToPhotosAlbum({
                    filePath: o.tempImagePath,
                    success: function(o) {
                        console.log(o), console.log("保存成功，进入选择"), wx.chooseImage({
                            count: 1,
                            type: "image",
                            sourceType: [ "album" ],
                            success: function(o) {
                                wx.uploadFile({
                                    url: t.url + "driver_order/plate_ocr&_acid=" + a.siteInfo.acid + "&access_token=" + wx.getStorageSync("access_token"),
                                    filePath: o.tempFilePaths[0],
                                    name: "file",
                                    success: function(t) {
                                        var o = JSON.parse(t.data);
                                        wx.hideLoading(), 1 == o.code ? (s.number = o.data.number, e.setData({
                                            data: s
                                        })) : a.showToast(o.msg, 0);
                                    }
                                });
                            }
                        });
                    },
                    file: function(a) {
                        console.log(a);
                    }
                });
            }
        });
    },
    click: function() {
        var t = this, e = t.data.data;
        wx.getLocation({
            success: function(o) {
                a.reverseGeocoder({
                    lat: o.latitude,
                    lng: o.longitude,
                    success: function(a) {
                        console.log(a), e.address = a.result.pois[0].address, e.name = a.result.pois[0].title, 
                        e.lat = a.result.pois[0].location.lat, e.lng = a.result.pois[0].location.lng, t.setData({
                            data: e
                        }), console.log(t.data.data);
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});